package com.lin.mr.maizilaundry.fragmentorder;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.lin.mr.maizilaundry.R;
import com.lin.mr.maizilaundry.entity.WaterfallInfo;
import com.lin.mr.maizilaundry.myadapter.SpacesItemDecoration;
import com.lin.mr.maizilaundry.myadapter.WaterfallAdapter;

import java.util.ArrayList;
import java.util.List;

public class FragmentCompleted extends Fragment {
    private RecyclerView recyclerView;
    private List<WaterfallInfo> waterfallInfoList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_completed, container, false);
        recyclerView = (RecyclerView) view.findViewById(R.id.recycleView);

        /**
         * 设置显示规则
         * arg0:列数；arg1:方向
         */
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.HORIZONTAL));
        //设置adapter
        WaterfallAdapter adapter = new WaterfallAdapter(getActivity(),getImageData());
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new WaterfallAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, int position) {
                WaterfallInfo waterfallInfo = waterfallInfoList.get(position);
                Toast.makeText(getActivity(), waterfallInfo.getName(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onItemLongClick(View view, int position) {
                Toast.makeText(getActivity(), "按这么久想干嘛(*^__^*)", Toast.LENGTH_SHORT).show();
            }
        });

        //设置item之间的间隔
        SpacesItemDecoration decoration=new SpacesItemDecoration(10);
        recyclerView.addItemDecoration(decoration);
        return view;
    }
    private List<WaterfallInfo> getImageData(){
        waterfallInfoList = new ArrayList<>();
        WaterfallInfo waterfallInfo1 = new WaterfallInfo(R.drawable.android1,"安卓机器人1");
        WaterfallInfo waterfallInfo2 = new WaterfallInfo(R.drawable.android8,"安卓机器人2");
        WaterfallInfo waterfallInfo3 = new WaterfallInfo(R.drawable.android3,"安卓机器人3");
        WaterfallInfo waterfallInfo4 = new WaterfallInfo(R.drawable.android4,"安卓机器人4");
        WaterfallInfo waterfallInfo5 = new WaterfallInfo(R.drawable.android9,"安卓机器人5");
        WaterfallInfo waterfallInfo6 = new WaterfallInfo(R.drawable.android6,"安卓机器人6");
        WaterfallInfo waterfallInfo7 = new WaterfallInfo(R.drawable.android7,"安卓机器人7");
        WaterfallInfo waterfallInfo8 = new WaterfallInfo(R.drawable.android8,"安卓机器人8");
        WaterfallInfo waterfallInfo9 = new WaterfallInfo(R.drawable.android9,"安卓机器人9");
        WaterfallInfo waterfallInfo10 = new WaterfallInfo(R.drawable.android10,"安卓机器人10");
        WaterfallInfo waterfallInfo11 = new WaterfallInfo(R.drawable.android11,"安卓机器人11");
        WaterfallInfo waterfallInfo12 = new WaterfallInfo(R.drawable.android12,"安卓机器人12");
        WaterfallInfo waterfallInfo13 = new WaterfallInfo(R.drawable.android13,"安卓机器人13");
        WaterfallInfo waterfallInfo14 = new WaterfallInfo(R.drawable.android14,"安卓机器人14");
        WaterfallInfo waterfallInfo15 = new WaterfallInfo(R.drawable.android15,"安卓机器人15");

        waterfallInfoList.add(waterfallInfo1);
        waterfallInfoList.add(waterfallInfo2);
        waterfallInfoList.add(waterfallInfo3);
        waterfallInfoList.add(waterfallInfo4);
        waterfallInfoList.add(waterfallInfo5);
        waterfallInfoList.add(waterfallInfo6);
        waterfallInfoList.add(waterfallInfo7);
        waterfallInfoList.add(waterfallInfo8);
        waterfallInfoList.add(waterfallInfo9);
        waterfallInfoList.add(waterfallInfo10);
        waterfallInfoList.add(waterfallInfo11);
        waterfallInfoList.add(waterfallInfo12);
        waterfallInfoList.add(waterfallInfo13);
        waterfallInfoList.add(waterfallInfo14);
        waterfallInfoList.add(waterfallInfo15);

        return waterfallInfoList;
    }


}
